/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.service;

import br.com.foxline.model.Configuracao;
import br.com.foxline.model.Parametro;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;

/**
 *
 * @author luciano
 */
@Stateless
public class ConfiguracaoService extends GenericService<Configuracao> {
    
     public ConfiguracaoService() {
        super(Configuracao.class);
    }
     
    public Configuracao getConfig(){
        List<Configuracao> configuracao = this.findAll();
        if(!configuracao.isEmpty()){
            return configuracao.get(0);
        }
        Configuracao configuracao1 = new Configuracao();
        configuracao1.setParametros(new ArrayList<Parametro>());
        return configuracao1;
    }
    
    public String getParameter(String key){
        Configuracao config = getConfig();
        for (Parametro parametro : config.getParametros()) {
            if(parametro.getName().equals(key)){
                return parametro.getValor();
            }
        }
        return "";
    }
     
}
